<%--
    Document   : search
    Created on : Jul 1, 2011, 9:00:25 AM
    Author     : PhongLK60473
--%>

<%@page import="Object.BookProperties.Type"%>
<%@page import="Object.BookProperties.Author"%>
<%@page import="Object.Page"%>
<%@page import="Object.Order"%>
<%@page import="Object.Book"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">       
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <style type="" >
            @import url("style/style.css");
            @import url("style/managebookauthors.style.css");
        </style>
    </head>
    <body>
        <%@include file="header.jsp" %>
        <%
                    if (!user.isAdmin()) {
                        response.sendRedirect("UserController");
                    }
        %>
        <div id="page">

        <% if(Page.isMessage(request)){ %>
            <div class="message"><%= Page.getMessage(request) %></div>
        <% } %>
        <div id="add-type">
                    <div class="header">
                        <a href="">
                            <img src="images/author_add.png"/>
                        Add New Authors
                        </a>
                    </div>
            <form action="ManagerController" method="POST" id="addForm">
                <div class="label">Name</div>
                <input type="text" name="txtName" id="add_name" value=""/>
                <input type="submit" name="action" value="Add Author"/>
            </form>
                    
            <script>
                document.getElementById("addForm").onsubmit=function(){
                    var vl = document.getElementById("add_name");
                    if(vl.value.trim()==""){
                        vl.focus();
                        return false;
                    }
                }
            </script>
            </div>
        <br>
        <%

            Author[] authors = Author.AllAuthors();
        %>

        <div id="search-result">
            <table border="1" class="books">
                <thead>
                    <tr class="title">
                        <th class=" Id">Id</td>
                        <th class=" Name">Name</td>
                        <th class=" Description">Description</td>
                        <th class="Action">Action</th>
                    </tr>
                </thead>
                <tbody>
                    <%
                    for(int i=0;i<authors.length;i++){
                        Author author=(Author) authors[i];
                    %>
                    <tr class="data">
                        <td class="Id"><%= author.getAuthorId() %></td>
                        <td class="Name"><form action="ManagerController" method="GET" id="f_edit_<%= author.getAuthorId() %>">
                                <input type="hidden" name="authorid" value="<%= author.getAuthorId() %>"/>
                                <input type="text" name="txtName" id="name_<%= author.getAuthorId() %>" value="<%= author.getAuthorName() %>"/>
                                <input type="submit" name="action" value="Edit Author"/>
                                <script>
                                    document.getElementById("f_edit_<%= author.getAuthorId() %>").onsubmit=function(){
                                        var vl = document.getElementById("name_<%= author.getAuthorId() %>");
                                        if(vl.value.trim()==""){
                                            vl.focus();
                                            return false;
                                        }
                                    }
                                </script>
                            </form>
                        </td>
                        <td class="Description"><%= author.getAuthorDescription() %></td>
                        <td class="Action">
                            <a href="ManagerController?action=DeleteAuthor&authorid=<%= author.getAuthorId() %>"><img src="images/author_delete.png"/></a>
                        </td>
                    </tr>
                    <%
                    }
                    %>
                </tbody>
            </table>
        </div>
        </div>
        <script>
            document.getElementById("add").onsubmit=function(){
                try {
                    if(document.getElementById("title").value.trim()==""){
                        document.getElementById("title").focus();
                        return false;
                    } else {
                        price = document.getElementById("price").value.trim();
                        if(price==""){
                            document.getElementById("price").focus();
                            return false;
                        }
                        
                        if(price/1!=price){
                            document.getElementById("price").value="";
                            document.getElementById("price").focus();
                            return false;
                        }
                    }
                }catch(e){
                    console.log(e);
                    return false;
                }
            return true;
            }

            document.onsubmit=function(e){
                
            }
        </script>
    </body>
</html>
